<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh','add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('xPotsq.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef">
            <!-- <template #columnPrepend>
                <el-table-column  type="expand">
                    <template #default="props">
                        <el-table :data="props.row.fp" :border="false">
                            <el-table-column width="80"/>
                            <el-table-column label="箱号" prop="TCNO" />
                            <el-table-column label="实际结束时间" prop="KTXTIME" />
                            <el-table-column label="开始时间" prop="STARTDATE" />
                            <el-table-column label="预计结束时间" prop="YJENDDATE" />
                            <el-table-column label="操作" >
                                <template #default="scope">

                                    <el-button class=".table-operate" type="danger" size="small" style="padding:4px 5px" @click="handleDelItem(scope.row)">
                                        <span><i class="fa fa-trash icon" style="font-size: 14px; color: rgb(255, 255, 255);"></i></span>
                                    </el-button>
                                </template>
                            </el-table-column>


                        </el-table>
                    </template>
                </el-table-column>
            </template> -->
        </Table>

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { xPotsq ,dEPARTMENT,authAdmin} from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import { i18n } from '/@/lang/index'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

const { t } = useI18n()
const tableRef = ref() 
// let optButtons = defaultOptButtons(["edit","delete"])
let optButtons = defaultOptButtons([])
let newButton: OptButton[] = [
    {
        render: 'tipButton',
        name: 'edit',
        title: 'edit',
        text: '',
        type: 'primary',
        icon: 'fa fa-pencil',
        class: 'table-row-edit',
        disabledTip: false,
        // 按钮是否显示，请返回布尔值
        display: (row: TableRow, field: TableColumn) => {
            return !-(row.TJFLAG)
        },
        // 按钮是否禁用，请返回布尔值
        // disabled: (row: TableRow, field: TableColumn) => {
        //     return false
        // },
        // 自定义el-button属性
        // attr: {}
    },
    {
        render: 'confirmButton',
        name: 'delete',
        title: 'delete',
        text: '',
        type: 'danger',
        icon: 'fa fa-trash',
        class: 'table-row-delete',
        disabledTip: false,
        popconfirm: {
            confirmButtonText: i18n.global.t('delete'),
            cancelButtonText: i18n.global.t('Cancel'),
            confirmButtonType: 'danger',
            title: i18n.global.t('Are you sure to delete the selected record?'),
        },
        // 按钮是否显示，请返回布尔值
        display: (row: TableRow, field: TableColumn) => {
            return !-(row.TJFLAG)
        },
        // 按钮是否禁用，请返回布尔值
        // disabled: (row: TableRow, field: TableColumn) => {
        //     return false
        // },
        // 自定义el-button属性
        // attr: {}
    },
]
optButtons = newButton.concat(optButtons)

const baTable = new baTableClass(
    new baTableApi(xPotsq),
    // new baTableApi(xPotsq, '_good/'),
    {
        pk: 'TKID',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('xPotsq.TKID'), prop: 'TKID', align: 'center', show: false },
            { label: t('xPotsq.CORP'), prop: 'CORP', align: 'center' },
            { label: t('xPotsq.YBH'), prop: 'YBH', align: 'center', show: false },
            { label: t('xPotsq.GOODSID'), prop: 'GOODSID', align: 'center', show: false },
            { label: t('xPotsq.GOODS'), prop: 'GOODS', align: 'center', show: false },
            { label: t('xPotsq.CONTYPE'), prop: 'codename', align: 'center',operator:false },
            { label: t('xPotsq.CONSUM'), prop: 'CONSUM', align: 'center', operator: 'RANGE' },
            { label: t('xStockin.DEPT'), prop: 'DEPTNAME', align: 'center',operator:false },
            { label: t('xStockin.DEPT'), prop: 'DEPT', align: 'center',show:false,comSearchRender: 'remoteSelect', remote: {
                pk:'DEPTID',
                field: 'DEPTNAME',
                remoteUrl:dEPARTMENT +'index',
                params: {},
            } },
            { label: t('xPotsq.YWTYPE'), prop: 'YWTYPE', align: 'center' },
            { label: t('xPotsq.CONSIZE'), prop: 'CONSIZE', align: 'center' },
            { label: t('xPotsq.TJFLAG'), prop: 'TJFLAG', align: 'center', render: 'tag',
            replaceValue: { '0': '未提交', '1': '已提交' }},
            { label: t('xPotsq.REMARK'), prop: 'REMARK', align: 'center' },
            { label: t('xPotsq.OP'), prop: 'OP', align: 'center' ,comSearchRender: 'remoteSelect', remote: {
                pk: 'nickname',
                field: 'nickname',
                remoteUrl:authAdmin+'index',
                params: {},
            } },
            { label: t('xPotsq.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'TKID', order: 'desc' },
    },
    {
        defaultItems: [],
    },
    {
        onTableDblclick: ({row}) => {
            // return !-(row.TJFLAG)
        }
    }
)

provide('baTable', baTable)

const route = useRoute()
onMounted(() => {
    baTable.table.ref = tableRef.value
    if(route.query.code){
        baTable.table.filter.code = route.query.code
    }
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})

const handleDelItem = (item:any)=>{
    console.log(item)
}
</script>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute } from 'vue-router'
export default defineComponent({
    name: 'xPotsq',
})
</script>

<style scoped lang="scss"></style>
